<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('调度日志列表')" />
	<style type="text/css">
     .layui-col-sm4 {width: 20%;}
	.badge-primary{background-color: #1ab394;color: #FFFFFF;}
    .badge{font-size: 11px;padding-bottom: 4px;padding-left: 6px;padding-right: 6px;text-shadow: none;display: inline-block;min-width: 10px;padding: 3px 7px;line-height: 1;text-align: center;white-space: nowrap;vertical-align: middle;border-radius: 10px;}
	</style>
</head>
<body class="no-skin">
 <div class="main-container" id="main-container">
    <div class="main-content">
        <div class="north">
            <div class="north-content">
                <form class="layui-form dis-ctr" >
                    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                        <div class="layui-form-item">
                            <div class="layui-inline layui-col-sm4">
                                <label class="layui-form-label">任务名称：</label>
                                <div class="layui-input-block">
                                    <input id="jobName-kw" type="text" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline layui-col-sm4" style="width:16%;">
                                <label class="layui-form-label">任务分组：</label>
                                <div class="layui-input-block">
                                    <select id="jobGroup-kw" name="jobGroup-kw">
                                        <option value="">所有</option>
                                        <option value="DEFAULT">默认</option>
                                        <option value="SYSTEM">系统</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline layui-col-sm4" style="width:16%;">
                                <label class="layui-form-label">任务状态：</label>
                                <div class="layui-input-block">
                                    <select id="status-kw" name="status-kw">
                                        <option value="">所有</option>
                                        <option value="0">正常</option>
                                        <option value="1">暂停</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline layui-col-sm4">
                                <label class="layui-form-label">执行时间：</label>
                                <div class="layui-input-block">
                                    <input style="display: none;" id="startTime" name="startTime">
                                    <input style="display: none;" id="endTime" name="endTime">
                                    <input id="time-kw" type="text" autocomplete="off" class="layui-input"><i class="dhicon dh-calendar icon_date_search"></i>
                                </div>
                            </div>
                            <div class="layui-inline layui-col-sm4">
                                <a class="layui-btn layuiadmin-btn-order dhicon dh-search" id="btn-search"><span class="fa_span">查询</span></a>
                                <button type="reset" class="layui-btn layui-btn-primary dhicon dh-refresh" id="dh-resets"><span class="fa_span">重置</span></button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div class="mid-content">
            <table class="layui-hide" id="dhTable" lay-filter="ftable"></table>
        </div>
    </div>
</div>
 <script type="text/html" id="toolbar">
  <div class="layui-btn-container">
	<a class="layui-btn layui-btn-danger layui-table-tools" id="clean" onclick="$.operate.clean()" shiro:hasPermission="common:job:delete"><i class="dhicon dh-trash"></i> 清空</a>
	<a class="layui-btn layui-table-tools" onclick="$.tablelist.exportExcel()" shiro:hasPermission="common:job:export"><i class="dhicon dh-download"></i> 导出</a>
  </div>
 </script>
 <script type="text/html" id="barDh">
	<a class="layui-btn layui-btn-xs dhicon dh-remove layui-btn-danger" onclick="remove('{{d.jobLogId}}')" shiro:hasPermission="common:job:delete"> 删除</a>
	<a class="layui-btn layui-btn-xs dhicon dh-search layui-btn-warm" onclick="$.operate.detail('{{d.jobLogId}}')" shiro:hasPermission="common:job:view"> 详细</a>
 </script>
 <script type="text/html" id="templet_jobGroup">
  {{# if(d.jobGroup=='DEFAULT'){ }}	默认{{# } }}
  {{# if(d.jobGroup=='SYSTEM'){ }}	系统{{# } }}
 </script>
 <th:block th:include="include :: footer" />
 <script th:inline="javascript">
	/*<![CDATA[*/
	var detailFlag = [[${@permission.hasPermi('common:job:detail')}]];
	var prefix = ctx + "common/jobLog";
    var jobId = [[${jobId}]];
	/*]]>*/
 </script>
 <script type="text/javascript">
  var $,layer,form,table,laydate,wherestr={};
  layui.use(['table','form','layer','jquery','laydate'], function () {
     $ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate=layui.laydate;
     $.tablelist.init({
         elem: '#dhTable'
         ,url: prefix + "/list?jobId="+jobId
         ,cleanUrl: prefix + "/clean"
         ,updateUrl: prefix + "/edit/{id}"
         ,detailUrl: prefix + "/detail/{id}"
         ,exportUrl: prefix + "/export"
	     ,modalName: "调度日志"
         ,initSort: {field: 'createTime',type: 'desc'}
         ,where: {
             field: 'createTime' //排序字段
             ,order: 'desc' //排序方式
         }
         ,cols: [[
        	{checkbox: true},
 	        {field: 'jobLogId',title: '日志编号',sort: true, width:100},
 	        {field: 'jobName',title: '任务名称',templet:'#templet_jobName',sort: true},
 	        {field: 'jobGroup',title: '任务分组', width:100,templet:function(d) {
 	        	if(d.jobGroup=='DEFAULT'){
 	        		return '默认';
 	        	}else if(d.jobGroup=='SYSTEM'){
 	        		return '系统';
 	        	}
            }},
 	        {field: 'invokeTarget',title: '调用目标字符串',formatter: function(value, row, index) {
 	            	return $.table.tooltip(value);
           	}},
 	        {field: 'jobMessage',title: '日志信息'},
 	        {field: 'status',title: '状态', width:120,align: 'center',templet:function(d) {
 	        	if(d.status==0){
 	        		return '<span class="badge badge-primary">成功</span>';
 	        	}else if(d.status==1){
 	        		return '<span class="badge badge-primary" style="background-color:red">失败</span>';
 	        	}
            }},
 	        {field: 'createTime',title: '执行时间',sort: true, width:150},
 	        {title: '操作',width:150,align: 'center',templet:'#barDh'}
 	    ]
     	]
        ,toolbar: '#toolbar'
        ,height:'full-' + ( $('.north').height()+36),
     });
     //监听排序事件
     table.on('sort(ftable)', function(obj){
         $.tablelist.sort('dhTable',obj);
     });
     //时间控件
     laydate.render({
        elem: '#time-kw',
        type:'datetime',
        range: '~',
        done: function (value, date, endDate) {
            var hours = endDate.hours;
            var minutes = endDate.minutes;
            var seconds = endDate.seconds;
            if (hours == "0" && minutes == "0" && seconds == "0"){
                $(".layui-laydate-footer [lay-type='datetime'].laydate-btns-time").click();
                // 改变结束时间默认值
                $(".laydate-main-list-1 .layui-laydate-content li ol li:last-child").click();
            }
            var splitArray = value.split('~');
            var startTime = (splitArray.length > 0) ? splitArray[0] :"";
            var endTime  =  (splitArray.length > 1) ?  splitArray[1] :"";
            $('#startTime').val(startTime);
            $('#endTime').val(endTime);
        }
    });
 	//表单重载方法
 	var active = {
         reload: function (formData) {
            wherestr = {
                jobName:$("#jobName-kw").val(),
                jobGroup:$("#jobGroup-kw").val(),
                status:$("#status-kw").val(),
                startTime:$("#startTime").val(),
                endTime:$("#endTime").val()
            };
             table.reload('dhTable', {
                 page: {
                     curr: 1 //重新从第 1 页开始
                 },
                 where: wherestr
             });
         },
     };
 	 //搜索
 	 $('#btn-search').on('click', function () {
         active['reload'].call(this);
     });
   });
    //删除
   function remove(jobId){
       $.operate.remove("确定要删除么？",prefix + "/remove",{'ids':jobId},function(result){
           allReload(result)
       });
   }
    //刷新
   function allReload(result){
     if(result.code==0){
        setTimeout(function(){
            layer.closeAll();
            table.reload('dhTable');
        }, 1000);
     }
   }
 </script>
</body>
</html>